package com.c.ctgproject.wiget.dialog

import android.os.Bundle
import android.view.View
import androidx.lifecycle.ViewModelProvider
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseDialogFragment
import com.c.ctgproject.utils.*
import kotlinx.android.synthetic.main.item_service_pay_type_dialog.*
import kotlinx.android.synthetic.main.item_service_return_record_dialog.*
import java.io.File

/**
 *作者:LiBW
 *创建日期: 2021/7/5
 *描述:回访记录输入 Dialog
 */
class InputReturnMessageDialog(private val suborderId: String, private val callback: InputReturnMessageDialogCallBack) : BaseDialogFragment() {

    private val mViewModel by lazy { ViewModelProvider(this)[InputReturnMessageViewModel::class.java] }
    override fun getLayout() = R.layout.item_service_return_record_dialog
    override fun viewIsCreated(view: View, savedInstanceState: Bundle?) {
        dialog?.setCanceledOnTouchOutside(false)
        mViewModel.error.observe(this, {
            MyLog.d("错误:$it")
            showToast(it)
        })

        mViewModel.result.observe(this, {
            MyLog.d("添加回访记录:$it")
            requireActivity().handlerHttpResult(it) {
                showToast("添加成功")
                callback.confirm()
            }
        })
        mAddBTN.setOnClickListener {
            val message=mMessageET.text.handlerNull()
            if (message.isEmpty()){
                showToast("请输入回访备注")
            }else{
                mViewModel.addReturnMessage(suborderId,message)
            }
        }
        mCancelBTN.setOnClickListener {
            dismiss()
        }

    }


    interface InputReturnMessageDialogCallBack {
        fun confirm()
    }
}